const fs = require("fs");
const path = require("path");
var readlineSync = require("readline-sync");
// 需要处理的目录
let filePath = "./";
let filterConditon = "";

let excuteRenameAction = function (filePath) {
  // filterConditon = readlineSync.question("Please input your str? ");
  let files = fs.readdirSync(path.join(__dirname, filePath));
  files.forEach((value, key) => {
    console.log(value);
    if (value === "rename.js") return;
    if (isFile(value)) {
      reName(value);
    }
  });
};

let isDir = function (dir) {
  if (fs.existsSync(dir)) {
    return fs.statSync(dir).isDirectory();
  }
};

let reName = function (oldName) {
  let newName = oldName.replace('【瑞 客  论 坛 www.ruike1.com】', "");
  fs.rename(oldName, newName, function (err) {
    if (err) {
      console.log(err);
      throw err;
    }
  });
};

let isFile = function (file) {
  if (fs.existsSync(file)) {
    return fs.statSync(file).isFile();
  }
};

let readFile = function (file) {
  if (fs.existsSync(file)) {
    return fs.readFileSync(file, "utf-8");
  }
};

excuteRenameAction(filePath);
